import axios from 'axios';

// 创建axios实例
var url = 'http://39.108.151.99/api/';

const service = axios.create({
    baseURL: url, // api的base_url
    timeout: 30000 // 请求超时时间 30000
});


// request拦截器
service.interceptors.request.use(config => {
    console.log('请求参数')
    console.log(config)
    return config;
}, error => {
    Promise.reject(error);
})



// respone拦截器
service.interceptors.response.use(
    response => {
        console.log(response, "===response====");
        const result = response.data.RESULT;
        console.log('code:' + result.RESULT_CODE);

        if (result.RESULT_CODE !== 1000) {
            console.log("reject");
            return Promise.reject(result);
        } else {
            console.log("resolve");
            return Promise.resolve(response.data.ROOT);
        }
    },
    error => {
        let ErrorMsg = error.message;
        if (error.code == 'ECONNABORTED') ErrorMsg = '请求超时，请稍后再试。';
        return Promise.reject(error);
    }
)

export default service;